//
//  LoginViewController.m
//  Unicorn
//
//  Created by xalo on 16/5/3.
//  Copyright © 2016年 bhj_jun. All rights reserved.
//

#import "LoginViewController.h"





@interface LoginViewController ()

@property (strong, nonatomic) IBOutlet UIImageView *backImg;

@property (strong, nonatomic) IBOutlet UIImageView *numberImg;//帐号img

@property (strong, nonatomic) IBOutlet UIImageView *passwordImg;//密码img

@property (strong, nonatomic) IBOutlet UIButton *LoginImg;//登录img

@property (strong, nonatomic) IBOutlet UIButton *forgetPwdBtn;//忘记密码btn

@property (strong, nonatomic) IBOutlet UIButton *qqLoginBtn;//qq登录

@property (strong, nonatomic) IBOutlet UIButton *sinaLoginBtn;//新浪登录

@property (strong, nonatomic) IBOutlet UITextField *numberTF;//请输入账号

@property (strong, nonatomic) IBOutlet UITextField *passwordTF;//请输入密码





@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"登录";
    
    [self viewSetting];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//界面属性设置
-(void)viewSetting
{
    self.LoginImg.layer.cornerRadius = 50;
    self.LoginImg.layer.masksToBounds = YES;
    
    self.numberImg.layer.cornerRadius = 15;
    self.numberImg.layer.masksToBounds = YES;
    
    self.passwordImg.layer.cornerRadius = 15;
    self.passwordImg.layer.masksToBounds = YES;
    
    self.qqLoginBtn.layer.cornerRadius = 30;
    self.qqLoginBtn.layer.masksToBounds = YES;
    self.sinaLoginBtn.layer.cornerRadius = 30;
    self.sinaLoginBtn.layer.masksToBounds = YES;
    
    self.numberTF.borderStyle = UITextBorderStyleNone;
    self.passwordTF.borderStyle = UITextBorderStyleNone;
    self.passwordTF.secureTextEntry = YES;
    
    self.navigationItem.leftBarButtonItem = ({
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"back"
                                                            style:UIBarButtonItemStylePlain target:self
                                                           action:@selector(itemAction:)];
        item;
    
    });
    
}


#pragma mark  - - 按钮事件
//返回事件
-(void)itemAction:(UIBarButtonItem *)sender
{
//    [self cancelAuthAction:nil];//QQ登录是否取消授权
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


//忘记密码事件
- (IBAction)forgetPwdAction:(UIButton *)sender {
}

//qq登录事件
- (IBAction)qqLoginBtnAction:(UIButton *)sender {
    
    [ShareSDK getUserInfo:SSDKPlatformTypeQQ onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        if (state == SSDKResponseStateSuccess) {
            NSLog(@"uid=%@",user.uid);
            NSLog(@"%@",user.credential);
            NSLog(@"token=%@",user.credential.token);
            NSLog(@"nickname=%@",user.nickname);
            NSLog(@"icon--%@",user.icon);
            NSLog(@"url---%@",user.url);
            NSLog(@"birthday---%@",user.birthday);
            NSLog(@"regAt---%f",(NSTimeInterval )user.regAt);
            
            [ShareSDK authorize:SSDKPlatformTypeQQ settings:@{SSDKAuthSettingKeyScopes:@[@"follow_app_official_microblog"]} onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
                
            }];
            
            BOOL isAuth=[ShareSDK hasAuthorized:(SSDKPlatformTypeQQ)];
            if (isAuth) {
                NSLog(@"isAutho--%d",isAuth);
            }   else
            {
                NSLog(@"未授权");
            }
            
        }else{
            NSLog(@"error---%ld",(long)error.code);
        }
        
    }];
  
}

/**取消QQ授权**/
-(void)cancelAuthAction:(UIButton *)sender
{
    [ShareSDK cancelAuthorize:SSDKPlatformTypeQQ];
    NSLog(@"QQ授权取消！");
}





//sina登录事件
- (IBAction)sinaLoginBtnAction:(UIButton *)sender {
    
    [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        
        if (state == SSDKResponseStateSuccess) {
            
            NSLog(@"uid=%@",user.uid);
            NSLog(@"%@",user.credential);
            NSLog(@"token=%@",user.credential.token);
            NSLog(@"nickname=%@",user.nickname);
            NSLog(@"icon--%@",user.icon);
            NSLog(@"url---%@",user.url);
            NSLog(@"birthday---%@",user.birthday);
            NSLog(@"regAt---%f",(NSTimeInterval )user.regAt);
            [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:@{SSDKAuthSettingKeyScopes:@[@"follow_app_official_microblog"]} onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
                
            }];
            
            BOOL isAuth = [ShareSDK hasAuthorized:SSDKPlatformTypeSinaWeibo];
            if (isAuth) {
                NSLog(@"sina_isAuth---%d",isAuth);
            }else
            {
                NSLog(@"sina未授权");
            }
        }else{
            NSLog(@"error－－－%ld",error.code);
        }
        
    }];
    
}


//取消第一响应(回收键盘)
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.numberTF resignFirstResponder];
    [self.passwordTF resignFirstResponder];
    
}




@end
